<?php

use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateVouchersTable extends Migration
{
    /**
     * 代金券
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('vouchers', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->index();
            $table->string('name')->default('抵扣券')->comment('代金券名称，抵扣券，兑换券');
            $table->string('type')->default('normal')->comment('代金券类别');
            $table->smallInteger('amount')->default(100)->comment('代金券金额');
            $table->dateTime('overtime')->default(Carbon::parse('+6 months')->toDateTimeString())->comment('失效时间');
            $table->tinyInteger('status')->default(0)->comment('当前状态：0：待激活；1：可使用，2：待兑换，3：已兑换，4：已失效');
            $table->string('description')->nullable()->comment('描述');
            $table->foreignId('user_id')->default(1)->constrained()
                ->onDelete('cascade')->comment('用户ID');
            $table->unsignedBigInteger('times')->default(0)->comment('流通次数');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('vouchers');
    }
}
